local shudao = fk.CreateSkill{
  name = "pegasus__shudao",
  tags = { Skill.Compulsory }
}

Fk:loadTranslationTable{
  ["pegasus__shudao"] = "书道",
  [":pegasus__shudao"] = "锁定技，你同一回合内使用第X张基本/非基本牌后（X为你的技能数），本回合获得“飞白”/“枯墨”。",
}

---@param player Player
---@return string[]
local getPlayerSkills = function (player)
  local skills = {}
  for _, s in ipairs(player.player_skills) do
    if s:isPlayerSkill(player) then
      table.insertIfNeed(skills, s.name)
    end
  end
  return skills
end

shudao:addEffect(fk.CardUsing, {
  anim_type = "special",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(shudao.name) and player == target then
      local events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function (e)
        if e.data.from == player then
          if data.card.type == Card.TypeBasic then
            return e.data.card.type == Card.TypeBasic
          else
            return e.data.card.type ~= Card.TypeBasic
          end
        end
      end, Player.HistoryTurn)

      return #events == #getPlayerSkills(player)
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local skill = data.card.type == Card.TypeBasic and "pegasus__feibai" or "pegasus__kumo"
    room:handleAddLoseSkills(player, skill)
    room:addTableMarkIfNeed(player, "pegasus__shudao", skill)
  end
})

shudao:addEffect(fk.TurnEnd, {
  can_refresh = function (self, event, target, player, data)
    return #player:getTableMark("pegasus__shudao") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local skills = player:getTableMark("pegasus__shudao")
    room:setPlayerMark(player, "pegasus__shudao", 0)
    room:handleAddLoseSkills(player, table.concat(table.map(skills, function (e) return "-" .. e end), "|"))
  end
})

return shudao